//
//  UniversalTableView.m
//  PublicSentimentMonitorSystem
//
//  Created by 郭斌 on 15/8/24.
//  Copyright (c) 2015年 魏强. All rights reserved.
//

#import "UniversalTableView.h"

@interface UniversalTableView () <UITableViewDataSource,UITableViewDelegate>
{

}
@end

@implementation UniversalTableView
-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self)
    {
        //初始化
        self.rowHeight = 40;
        self.dataArray = [NSArray array];
        self.tableFooterView = [[UIView alloc] init];
        self.delegate = self;
        self.dataSource = self;
    }
    return self;
}

#pragma mark - tableview返回行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }
    
    if(self.dataArray.count > 0)
    {
        //NSLog(@"%@",kindArr);
        cell.textLabel.text = self.dataArray[indexPath.row];
        //定制cell右按钮
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

#pragma mark - 当单元格被选中
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *indexT = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
    
    NSDictionary *userInfo11b = [[NSDictionary alloc] initWithObjectsAndKeys:indexT,@"index",self.dataArray[indexPath.row],@"TypeName",self.whichTable,@"whichTable",nil];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"SelectTheAnyType" object:nil userInfo:userInfo11b];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
